1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Data;
5 using
System.Drawing;
6 using
System.Linq;
7 using
System.Text;
8 using
System.Windows.Forms;
9 using
System.Data.SqlClient;
10 using
System.Security.Cryptography;
11 using
CrystalDecisions.Shared;
12 using
CrystalDecisions.CrystalReports.Engine;
13 namespace
WarehouseManagementSystem
14 {
15     
public partial class frmSales : Form
16     {
17         SqlCommand cmd;
18         SqlConnection con;
19         SqlDataReader rdr;
20         ConnectionString cs =
new ConnectionString();
21
22         
public frmSales()
23         {
24             InitializeComponent();
25         }
26         
private void auto()
27         {
28             txtInvoiceNo.Text =
"OD-" + GetUniqueKey(8);
29
30         }
31         
public static string GetUniqueKey(int maxSize)
32         {
33             
char[] chars = new char[62];
34             chars =
"123456789".ToCharArray();
35             
byte[] data = new byte[1];
36             RNGCryptoServiceProvider crypto =
new RNGCryptoServiceProvider();
37             crypto.GetNonZeroBytes(data);
38             data =
new byte[maxSize];
39             crypto.GetNonZeroBytes(data);
40             StringBuilder result =
new StringBuilder(maxSize);
41             
foreach (byte b in data)
42             {
43                 result.Append(chars[b % (chars.Length)]);
44             }
45             
return result.ToString();
46         }
47
48         
private void Save_Click(object sender, EventArgs e)
49         {
50             
try
51             {
52                 
if (txtCustomerID.Text == "")
53                 {
54                     MessageBox.Show(
"Please retrieve Customer Details", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
55                     Button1.Focus();
56                     
return;
57                 }
58
59                 
if (txtTaxPer.Text == "")
60                 {
61                     MessageBox.Show(
"Please enter tax percentage", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
62                     txtTaxPer.Focus();
63                     
return;
64                 }
65                  
if (txtDiscountPer.Text == "")
66                 {
67                     MessageBox.Show(
"Please enter discount percentage", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
68                     txtDiscountPer.Focus();
69                     
return;
70                 }
71                 
if (txtTotalPayment.Text == "")
72                 {
73                     MessageBox.Show(
"Please enter total payment", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
74                     txtTotalPayment.Focus();
75                     
return;
76                 }
77                  
if (cmbPaymentType.Text == "")
78                 {
79                     MessageBox.Show(
"Please select payment type", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
80                     cmbPaymentType.Focus();
81                     
return;
82                 }
83                  
if (cmbStatus.Text == "")
84                 {
85                     MessageBox.Show(
"Please select status", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
86                     cmbStatus.Focus();
87                     
return;
88                 }
89                 
if (ListView1.Items.Count == 0)
90                 {
91                     MessageBox.Show(
"sorry no product added", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
92                     
return;
93                 }
94
95                 auto();
96                
97                 con =
new SqlConnection(cs.DBConn);
98                 con.Open();
99
100                 
string cb = "insert Into Invoice_Info(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPer,VATAmount,DiscountPer,DiscountAmount,GrandTotal,TotalPayment,PaymentDue,PaymentType,Status,Remarks) VALUES ('" + txtInvoiceNo.Text + "','" + dtpInvoiceDate.Text + "','" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + ","+ txtDiscountPer.Text +","+ txtDiscountAmount.Text +"," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + cmbPaymentType.Text + "','"+ cmbStatus.Text + "','" + txtRemarks.Text + "')";
101                 cmd =
new SqlCommand(cb);
102                 cmd.Connection = con;
103                 cmd.ExecuteReader();
104                 
if (con.State == ConnectionState.Open)
105                 {
106                     con.Close();
107                 }
108                 con.Close();
109
110
111                 
for (int i = 0; i <= ListView1.Items.Count - 1; i++)
112                 {
113                     con =
new SqlConnection(cs.DBConn);
114
115                     
string cd = "insert Into ProductSold(InvoiceNo,ProductID,ProductName,Quantity,Price,TotalAmount) VALUES (@d1,@d2,@d3,@d4,@d5,@d6)";
116                     cmd =
new SqlCommand(cd);
117                     cmd.Connection = con;
118                     cmd.Parameters.AddWithValue(
"d1", txtInvoiceNo.Text);
119                     cmd.Parameters.AddWithValue(
"d2", ListView1.Items[i].SubItems[1].Text);
120                     cmd.Parameters.AddWithValue(
"d3", ListView1.Items[i].SubItems[2].Text);
121                     cmd.Parameters.AddWithValue(
"d4", ListView1.Items[i].SubItems[4].Text);
122                     cmd.Parameters.AddWithValue(
"d5", ListView1.Items[i].SubItems[3].Text);
123                     cmd.Parameters.AddWithValue(
"d6", ListView1.Items[i].SubItems[5].Text);
124                     con.Open();
125                     cmd.ExecuteNonQuery();
126                     con.Close();
127                 }
128                 
for (int i = 0; i <= ListView1.Items.Count - 1; i++)
129                 {
130                     con =
new SqlConnection(cs.DBConn);
131                     con.Open();
132                     
string cb1 = "update temp_stock set Quantity = Quantity - " + ListView1.Items[i].SubItems[4].Text + " where ProductID= '" + ListView1.Items[i].SubItems[1].Text + "'";
133                     cmd =
new SqlCommand(cb1);
134                     cmd.Connection = con;
135                     cmd.ExecuteNonQuery();
136                     con.Close();
137                 }
138                
139                 Save.Enabled =
false;
140                 btnPrint.Enabled =
true;
141                 GetData();
142                 MessageBox.Show(
"Successfully Placed", "Order", MessageBoxButtons.OK, MessageBoxIcon.Information);
143             }
144             
catch (Exception ex)
145             {
146                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
147             }
148         }
149
150         
private void frmInvoice_Load(object sender, EventArgs e)
151         {
152             GetData();
153         }
154
155         
private void Button1_Click(object sender, EventArgs e)
156         {
157             
this.Hide();
158             frmCustomersRecord1 frm =
new frmCustomersRecord1();
159             frm.lblUser.Text = lblUser.Text;
160             frm.lblUserType.Text = lblUserType.Text;
161             frm.Visible=
true;
162         }
163
164       
public void Calculate()
165         {
166             
if (txtTaxPer.Text != "")
167             {
168                 txtTaxAmt.Text = Convert.ToInt32((Convert.ToInt32(txtSubTotal.Text) * Convert.ToDouble(txtTaxPer.Text) /
100)).ToString();
169                 
170             }
171             
if (txtDiscountPer.Text != "")
172             {
173                 txtDiscountAmount.Text = Convert.ToInt32(((Convert.ToInt32(txtSubTotal.Text) + Convert.ToInt32(txtTaxAmt.Text)) * Convert.ToDouble(txtDiscountPer.Text) /
100)).ToString();
174             }
175             
int val1 = 0;
176             
int val2 = 0;
177             
int val3 = 0;
178             
int val4 = 0;
179             
int val5= 0;
180             
int.TryParse(txtTaxAmt.Text, out val1);
181             
int.TryParse(txtSubTotal.Text, out val2);
182             
int.TryParse(txtDiscountAmount.Text, out val3);
183             
int.TryParse(txtTotal.Text, out val4);
184             
int.TryParse(txtTotalPayment.Text, out val5);
185             val4 = val1 + val2 - val3;
186             txtTotal.Text = val4.ToString();
187             
int I = (val4 - val5);
188             txtPaymentDue.Text = I.ToString();
189
190
191         }
192         
private void txtSaleQty_TextChanged(object sender, EventArgs e)
193         {
194             
int val1 = 0;
195             
int val2 = 0;
196             
int.TryParse(txtPrice.Text, out val1);
197             
int.TryParse(txtSaleQty.Text, out val2);
198             
int I = (val1 * val2);
199             txtTotalAmount.Text = I.ToString();
200         }
201
202         
public double subtot()
203         {
204             
int i = 0;
205             
int j = 0;
206             
int k = 0;
207             i =
0;
208             j =
0;
209             k =
0;
210
211
212             
try
213             {
214            
215                 j = ListView1.Items.Count;
216                 
for (i = 0; i <= j - 1; i++)
217                 {
218                     k = k + Convert.ToInt32(ListView1.Items[i].SubItems[
5].Text);
219                 }
220                
221             }
222
223             
catch (Exception ex)
224             {
225                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
226             }
227             
return k;
228
229         }
230
231         
private void Button7_Click(object sender, EventArgs e)
232         {
233             
try
234             {
235                 
if (txtCustomerID.Text == "")
236                 {
237                     MessageBox.Show(
"Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
238                     txtCustomerID.Focus();
239                     
return;
240                 }
241
242                 
if (txtProductName.Text=="")
243                 {
244                     MessageBox.Show(
"Please retrieve product name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
245                     
return;
246                 }
247                 
if (txtSaleQty.Text=="")
248                 {
249                     MessageBox.Show(
"Please enter no. of sale quantity", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
250                     txtSaleQty.Focus();
251                     
return;
252                 }
253                 
int SaleQty = Convert.ToInt32(txtSaleQty.Text);
254                 
if (SaleQty == 0)
255                 {
256                     MessageBox.Show(
"no. of sale quantity can not be zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
257                     txtSaleQty.Focus();
258                     
return;
259                 }
260               
261                 
if (ListView1.Items.Count==0)
262                 {
263                    
264                     ListViewItem lst =
new ListViewItem();
265                     lst.SubItems.Add(txtProductID.Text);
266                     lst.SubItems.Add(txtProductName.Text);
267                     lst.SubItems.Add(txtPrice.Text);
268                     lst.SubItems.Add(txtSaleQty.Text);
269                     lst.SubItems.Add(txtTotalAmount.Text);
270                     ListView1.Items.Add(lst);
271                     txtSubTotal.Text = subtot().ToString();
272                   
273                     Calculate();
274                     txtProductName.Text =
"";
275                     txtProductID.Text =
"";
276                     txtPrice.Text =
"";
277                     txtAvailableQty.Text =
"";
278                     txtSaleQty.Text =
"";
279                     txtTotalAmount.Text =
"";
280                     txtProduct.Text =
"";
281                     
return;
282                 }
283
284                 
for (int j = 0; j <= ListView1.Items.Count - 1; j++)
285                 {
286                     
if (ListView1.Items[j].SubItems[1].Text == txtProductID.Text)
287                     {
288                         ListView1.Items[j].SubItems[
1].Text = txtProductID.Text;
289                         ListView1.Items[j].SubItems[
2].Text = txtProductName.Text;
290                         ListView1.Items[j].SubItems[
3].Text = txtPrice.Text;
291                         ListView1.Items[j].SubItems[
4].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[4].Text) + Convert.ToInt32(txtSaleQty.Text)).ToString();
292                         ListView1.Items[j].SubItems[
5].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[5].Text) + Convert.ToInt32(txtTotalAmount.Text)).ToString();
293                         txtSubTotal.Text = subtot().ToString();
294                         Calculate();
295                         txtProductName.Text =
"";
296                         txtProductID.Text =
"";
297                         txtPrice.Text =
"";
298                         txtAvailableQty.Text =
"";
299                         txtSaleQty.Text =
"";
300                         txtTotalAmount.Text =
"";
301                         
return;
302
303                     }
304                 }
305                    
306                     ListViewItem lst1 =
new ListViewItem();
307
308                     lst1.SubItems.Add(txtProductID.Text);
309                     lst1.SubItems.Add(txtProductName.Text);
310                     lst1.SubItems.Add(txtPrice.Text);
311                     lst1.SubItems.Add(txtSaleQty.Text);
312                     lst1.SubItems.Add(txtTotalAmount.Text);
313                     ListView1.Items.Add(lst1);
314                     txtSubTotal.Text = subtot().ToString();
315                     Calculate();
316                     txtProductName.Text =
"";
317                     txtProductID.Text =
"";
318                     txtPrice.Text =
"";
319                     txtAvailableQty.Text =
"";
320                     txtSaleQty.Text =
"";
321                     txtTotalAmount.Text =
"";
322                     
return;
323             }
324             
catch (Exception ex)
325             {
326                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
327             }
328         }
329
330         
private void btnRemove_Click(object sender, EventArgs e)
331         {
332             
try
333             {
334                 
if (ListView1.Items.Count == 0)
335                 {
336                     MessageBox.Show(
"No items to remove", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
337                 }
338                 
else
339                 {
340                     
int itmCnt = 0;
341                     
int i = 0;
342                     
int t = 0;
343
344                     ListView1.FocusedItem.Remove();
345                     itmCnt = ListView1.Items.Count;
346                     t =
1;
347
348                     
for (i = 1; i <= itmCnt + 1; i++)
349                     {
350                         
//Dim lst1 As New ListViewItem(i)
351                         
//ListView1.Items(i).SubItems(0).Text = t
352                         t = t +
1;
353
354                     }
355                     txtSubTotal.Text = subtot().ToString();
356                     Calculate();
357                 }
358
359                 btnRemove.Enabled =
false;
360                 
if (ListView1.Items.Count == 0)
361                 {
362                     txtSubTotal.Text =
"";
363                 }
364             }
365             
catch (Exception ex)
366             {
367                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
368             }
369         }
370
371         
private void txtTaxPer_TextChanged(object sender, EventArgs e)
372         {
373             
try
374             {
375                 
if (string.IsNullOrEmpty(txtTaxPer.Text))
376                 {
377                     txtTaxAmt.Text =
"";
378                     txtTotal.Text =
"";
379                     
return;
380                 }
381                 Calculate();
382             }
383             
catch (Exception ex)
384             {
385                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
386             }
387         }
388
389         
private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
390         {
391             btnRemove.Enabled =
true;
392         }
393
394         
private void textBox1_TextChanged(object sender, EventArgs e)
395         {
396             
try
397             {
398                 con =
new SqlConnection(cs.DBConn);
399                 con.Open();
400                 String sql =
"SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
401                 cmd =
new SqlCommand(sql, con);
402                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
403                 dataGridView1.Rows.Clear();
404                 
while (rdr.Read() == true)
405                 {
406                     dataGridView1.Rows.Add(rdr[
0], rdr[1], rdr[2], rdr[3], rdr[4]);
407                 }
408                 con.Close();
409             }
410             
catch (Exception ex)
411             {
412                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
413             }
414         }
415
416         
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
417         {
418             
string strRowNumber = (e.RowIndex + 1).ToString();
419             SizeF size = e.Graphics.MeasureString(strRowNumber,
this.Font);
420             
if (dataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
421             {
422                 dataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width +
20));
423             }
424             Brush b = SystemBrushes.ControlText;
425             e.Graphics.DrawString(strRowNumber,
this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
426      
427         }
428
429         
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
430         {
431             
try
432             {
433                 DataGridViewRow dr = dataGridView1.SelectedRows[
0];
434                 txtProductID.Text = dr.Cells[
0].Value.ToString();
435                 txtProductName.Text = dr.Cells[
1].Value.ToString();
436                 txtPrice.Text = dr.Cells[
3].Value.ToString();
437                 txtAvailableQty.Text = dr.Cells[
4].Value.ToString();
438                 txtSaleQty.Focus();
439             }
440             
catch (Exception ex)
441             {
442                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
443             }
444         }
445         
public void GetData()
446         {
447             
try
448             {
449                 con =
new SqlConnection(cs.DBConn);
450                 con.Open();
451                 String sql =
"SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
452                 cmd =
new SqlCommand(sql, con);
453                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
454                 dataGridView1.Rows.Clear();
455                 
while (rdr.Read() == true)
456                 {
457                     dataGridView1.Rows.Add(rdr[
0], rdr[1], rdr[2], rdr[3],rdr[4]);
458                 }
459                 con.Close();
460             }
461             
catch (Exception ex)
462             {
463                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
464             }
465         }
466         
private void Reset()
467         {
468             txtInvoiceNo.Text =
"";
469             cmbStatus.Text =
"";
470             cmbPaymentType.Text =
"";
471             dtpInvoiceDate.Text = DateTime.Today.ToString();
472             txtCustomerID.Text =
"";
473             txtCustomerName.Text =
"";
474             txtProductName.Text =
"";
475             txtProductID.Text =
"";
476             txtPrice.Text =
"";
477             txtAvailableQty.Text =
"";
478             txtSaleQty.Text =
"";
479             txtTotalAmount.Text =
"";
480             ListView1.Items.Clear();
481             txtDiscountAmount.Text =
"";
482             txtDiscountPer.Text =
"";
483
484             txtSubTotal.Text =
"";
485             txtTaxPer.Text =
"";
486             txtTaxAmt.Text =
"";
487             txtTotal.Text =
"";
488             txtTotalPayment.Text =
"";
489             txtPaymentDue.Text =
"";
490             txtProduct.Text =
"";
491             txtRemarks.Text =
"";
492             Save.Enabled =
true;
493             Delete.Enabled =
false;
494             btnUpdate.Enabled =
false;
495             btnRemove.Enabled =
false;
496             btnPrint.Enabled =
false;
497             ListView1.Enabled =
true;
498             Button7.Enabled =
true;
499
500         }
501
502         
private void NewRecord_Click(object sender, EventArgs e)
503         {
504             Reset();
505             Reset();
506         }
507
508         
private void Delete_Click(object sender, EventArgs e)
509         {
510             
if (MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
511             {
512                 delete_records();
513             }
514         }
515         
private void delete_records()
516         {
517
518             
try
519             {
520
521                 
int RowsAffected = 0;
522                 con =
new SqlConnection(cs.DBConn);
523                 con.Open();
524                 
string cq1 = "delete from productSold where InvoiceNo='" + txtInvoiceNo.Text + "'";
525                 cmd =
new SqlCommand(cq1);
526                 cmd.Connection = con;
527                 RowsAffected = cmd.ExecuteNonQuery();
528                 con.Close();
529                 con =
new SqlConnection(cs.DBConn);
530                 con.Open();
531                 
string cq = "delete from Invoice_Info where InvoiceNo='" + txtInvoiceNo.Text + "'";
532                 cmd =
new SqlCommand(cq);
533                 cmd.Connection = con;
534                 RowsAffected = cmd.ExecuteNonQuery();
535                 
if (RowsAffected > 0)
536                 {
537                     MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
538                     Reset();
539                 }
540                 
else
541                 {
542                     MessageBox.Show(
"No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information);
543                     Reset();
544                 }
545                 
if (con.State == ConnectionState.Open)
546                 {
547                     con.Close();
548                 }
549
550
551             }
552             
catch (Exception ex)
553             {
554                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
555             }
556         }
557
558         
private void frmInvoice_FormClosing(object sender, FormClosingEventArgs e)
559         {
560             
this.Hide();
561             frmMainMenu frm =
new frmMainMenu();
562             frm.lblUser.Text = lblUser.Text;
563             frm.lblUserType.Text = lblUserType.Text;
564             frm.Show();
565         }
566
567         
private void txtTotalPayment_TextChanged(object sender, EventArgs e)
568         {
569             
int val1 = 0;
570             
int val2 = 0;
571             
int.TryParse(txtTotal.Text, out val1);
572             
int.TryParse(txtTotalPayment.Text, out val2);
573             
int I = (val1 - val2);
574             txtPaymentDue.Text = I.ToString();
575         }
576
577         
private void txtTotalPayment_Validating(object sender, CancelEventArgs e)
578         {
579             
int val1 = 0;
580             
int val2 = 0;
581             
int.TryParse(txtTotal.Text, out val1);
582             
int.TryParse(txtTotalPayment.Text, out val2);
583             
if (val2 > val1)
584             {
585                 MessageBox.Show(
"Total Payment can't be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
586                 txtTotalPayment.Text =
"";
587                 txtPaymentDue.Text =
"";
588                 txtTotalPayment.Focus();
589                 
return;
590             }
591         }
592
593         
private void txtSaleQty_Validating(object sender, CancelEventArgs e)
594         {
595
596             
int val1 = 0;
597             
int val2 = 0;
598             
int.TryParse(txtAvailableQty.Text, out val1);
599             
int.TryParse(txtSaleQty.Text, out val2);
600             
if (val2 > val1)
601             {
602                 MessageBox.Show(
"Selling quantities are more than available quantities", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
603                 txtSaleQty.Text =
"";
604                 txtTotalAmount.Text =
"";
605                 txtSaleQty.Focus();
606                 
return;
607             }
608         }
609
610         
private void btnPrint_Click(object sender, EventArgs e)
611         {
612             
try
613             {
614                 Cursor = Cursors.WaitCursor;
615                 timer1.Enabled =
true;
616                 rptInvoice rpt =
new rptInvoice();
617                 
//The report you created.
618                 cmd =
new SqlCommand();
619                 SqlDataAdapter myDA =
new SqlDataAdapter();
620                 POS_DBDataSet myDS =
new POS_DBDataSet();
621                 
//The DataSet you created.
622                 con =
new SqlConnection(cs.DBConn);
623                 cmd.Connection = con;
624                 cmd.CommandText =
"SELECT * from product,invoice_info,productsold,customer where invoice_info.invoiceno=productsold.invoiceno and invoice_info.customerID=Customer.CustomerID and ProductSold.ProductID=Product.ProductID and Invoice_info.invoiceNo='" + txtInvoiceNo.Text + "'";
625                 cmd.CommandType = CommandType.Text;
626                 myDA.SelectCommand = cmd;
627                 myDA.Fill(myDS,
"product");
628                 myDA.Fill(myDS,
"Invoice_Info");
629                 myDA.Fill(myDS,
"ProductSold");
630                 myDA.Fill(myDS,
"Customer");
631                 rpt.SetDataSource(myDS);
632                 frmInvoiceReport frm =
new frmInvoiceReport();
633                 frm.crystalReportViewer1.ReportSource = rpt;
634                 frm.Visible=
true;
635             }
636             
catch (Exception ex)
637             {
638                 MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
639             }
640         }
641
642         
private void timer1_Tick(object sender, EventArgs e)
643         {
644             Cursor = Cursors.Default;
645             timer1.Enabled =
false;
646         }
647
648         
private void btnUpdate_Click(object sender, EventArgs e)
649         {
650             
try
651             {
652             con =
new SqlConnection(cs.DBConn);
653             con.Open();
654             String cb =
"update Invoice_info set CustomerID='" + txtCustomerID.Text + "', VATPer="+ txtTaxPer.Text +",VATAmount=" + txtTaxAmt.Text +",DiscountPer="+ txtDiscountPer.Text +",DiscountAmount="+ txtDiscountAmount.Text +",GrandTotal= " + txtTotal.Text + ",TotalPayment= " + txtTotalPayment.Text + ",PaymentDue= " + txtPaymentDue.Text + ",Remarks='" + txtRemarks.Text + "',Status='" + cmbStatus.Text + "',PaymentType='" + cmbPaymentType.Text + "' where Invoiceno= '" + txtInvoiceNo.Text + "'";
655             cmd =
new SqlCommand(cb);
656             cmd.Connection = con;
657             cmd.ExecuteReader();
658             con.Close();
659           
660             GetData();
661             btnUpdate.Enabled =
false;
662             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
663             }
664         
catch (Exception ex)
665             {
666             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
667             }
668         }
669
670         
private void Button4_Click(object sender, EventArgs e)
671         {
672             
this.Hide();
673             frmSalesRecord1 frm =
new frmSalesRecord1();
674             frm.DataGridView1.DataSource =
null;
675             frm.dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
676             frm.dtpInvoiceDateTo.Text = DateTime.Today.ToString();
677             frm.GroupBox3.Visible =
false;
678             frm.DataGridView3.DataSource =
null;
679             frm.cmbCustomerName.Text =
"";
680             frm.GroupBox4.Visible =
false;
681             frm.DateTimePicker1.Text = DateTime.Today.ToString();
682             frm.DateTimePicker2.Text = DateTime.Today.ToString();
683             frm.DataGridView2.DataSource =
null;
684             frm.GroupBox10.Visible =
false;
685             frm.FillCombo();
686             frm.lblUser.Text = lblUser.Text;
687             frm.lblUserType.Text = lblUserType.Text;
688             frm.Show();
689         }
690
691         
private void txtSaleQty_KeyPress(object sender, KeyPressEventArgs e)
692         {
693             
if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
694             {
695                 e.Handled =
false;
696             }
697             
else
698             {
699                 e.Handled =
true;
700             }
701         }
702
703         
private void txtTotalPayment_KeyPress(object sender, KeyPressEventArgs e)
704         {
705             
if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
706             {
707                 e.Handled =
false;
708             }
709             
else
710             {
711                 e.Handled =
true;
712             }
713         }
714
715         
private void txtTaxPer_KeyPress(object sender, KeyPressEventArgs e)
716         {
717             
// allows 0-9, backspace, and decimal
718             
if (((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 46))
719             {
720                 e.Handled =
true;
721                 
return;
722             }
723         }
724
725         
private void txtDiscountPer_TextChanged(object sender, EventArgs e)
726         {
727             Calculate();
728         }
729     }
730 }


Gõ tìm kiếm nhanh...